/** {{ handle.name }} **/
function {{ handle.name }}(opts) {
  this.memoryBuffer = null;
  this.memoryAddress = BI0;
  this.memoryOffset = 0x0;

  if (opts !== void 0) {
    if (opts.$memoryBuffer === void 0) {
      throw new Error("'{{ handle.name }}' doesn't take any arguments");
    }
    else {
      if (opts.$memoryOffset !== void 0) {
        let addr = getAddressFromArrayBuffer(opts.$memoryBuffer);
        this.memoryBuffer = getArrayBufferFromAddress(addr + BigInt(opts.$memoryOffset), BI8);
        this.memoryOffset = opts.$memoryOffset;
      } else {
        this.memoryBuffer = opts.$memoryBuffer;
      }
    }
  }
  else {
    this.memoryBuffer = new ArrayBuffer({{ getHandleByteLength() | safe }});
  }
  this.memoryAddress = getAddressFromArrayBuffer(this.memoryBuffer);
  this.memoryView = new DataView(this.memoryBuffer, 0x0, {{ getHandleByteLength() | safe }});
};

{{ handle.name }}.prototype.reflect = function reflect(memoryAddress) {
  let srcBuffer = getArrayBufferFromAddress(memoryAddress, BigInt({{ getHandleByteLength() | safe }}));
  let dstBuffer = this.memoryBuffer;
  let srcView = new Uint8Array(srcBuffer);
  let dstView = new Uint8Array(dstBuffer);
  //console.log(`Reflect: "{{ handle.name }}"`, this.memoryAddress, memoryAddress);
  dstView.set(srcView, 0x0);
};

{{ handle.name }}.byteLength = {{ getHandleByteLength() | safe }};
